<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<link rel="stylesheet" type="text/css" href="../resource/Css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="../resource/datatable/css/jquery.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="../resource/Select/css/select.dataTables.min.css" />
<link rel="stylesheet" type="text/css" href="../resource/aui-artDialog/css/ui-dialog.css" />
<link rel="stylesheet" type="text/css" href="../resource/Css/base.css" />
<link rel="stylesheet" href="../resource/Font-Awesome/css/font-awesome.css" />


<script type="text/javascript" src="../resource/Js/jquery.js"></script>
<script type="text/javascript" src="../resource/datatable/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="../resource/Select/js/dataTables.select.min.js" ></script >
<script type="text/javascript" src="../resource/aui-artDialog/dist/dialog.js"></script>
<script type="text/javascript" src="../resource/aui-artDialog/dist/dialog-plus.js"></script>
<script type="text/javascript" src="../resource/Js/bootstrap.js"></script>
<script type="text/javascript" src="../resource/Js/common.js"></script>
</head>
<body>
	<div class="fluid filterForm">
		<form action="" class="form-horizontal form-search">
			<ul class="formRow">
				<#list listx as x>
				   <#if x.condition!='0'>
				   <#if x.codeType==''>
				   <li class="control-group "><label class="control-label">${x.label}：</label>
					<div class="controls">
						<input type="text" id="${x.name}ForSearch" maxlength="80">
					</div></li>
					<#else>
				    <li class="control-group "><label class="control-label">${x.label}：</label>
					<div class="controls">
						<select class="form-control" id="${x.name}ForSearch" defaultValue="${x.name}">
							<option value="">请选择...</option>
						</select>
					</div></li>
					</#if>
					</#if>
			   </#list>
				<li class="control-group  ">
					<div class="btn-div">
						<a href="javascript:void(0)" id="btn-search" class="btn btn-small btn-primary"> <i class="fa fa-search "></i> 查询
						</a>
					</div>
				</li>
			</ul>

		</form>
	</div>
	<div class="btn-group btn-toolbar">
		<a href="javascript:void(0)" id="btn-add" class="btn btn-small btn-success"> <i class="fa fa-plus "></i> 新增
		</a> <a href="javascript:void(0)" id="btn-delete" class="btn btn-small btn-danger"> <i class="fa fa-trash "></i> 删除
		</a>
	</div>
	<div>
		<table id="${e.javaName?uncap_first}Table" class="table table-striped table-bordered table-hover" cellspacing="0" width="100%">
			<thead>
				<tr>
				<th id= "ath"> </th>
				<#list listx as x>
				   <#if x.visiable='1'>
				     <th>${x.label}</th>
					</#if>
			   </#list>
			         <th>操作</th>
				</tr>
			</thead>
		</table>
	</div>
	
	<div style="display: none;" id="edit-dialog" class="fluid filterForm">
		<form id="editForm" action="#" class="form-horizontal form-input" >
			<input type="hidden" id="${e.primaryColumn.name}ForEdit" >
			<ul class="formRow">
			<#list listx as x>
				   <#if x.insertAble=='1'>
				    <#if x.codeType == ''>
						<#if x.longChar=='1'>
						  <li class="control-group cols2"><label class="control-label">${x.label}：</label>
						<div class="controls">
						<textarea class="cols2"  cols="20" id="${x.name}ForEdit"></textarea>
						  <#else>
						   <li class="control-group "><label class="control-label">${x.label}：</label>
						<div class="controls">
						<input type="text" id="${x.name}ForEdit" maxlength="80">
					    </#if>	
						</div></li>
					<#else>
					    <li class="control-group "><label class="control-label">${x.label}：</label>
						<div class="controls">
							<select class="form-control" id="${x.name}ForEdit" defaultValue="${x.name}">
								<option value="">请选择...</option>
							</select>
						</div></li>
					</#if>
					</#if>
					
			 </#list>
			 </ul>
		</form>
	</div>
</body>
</html>
<script>
	var table = null;
	$(function() {
	      var selectAll = false;
           $( '#ath').click( function() {
                 if(selectAll){
                      table.rows().deselect();
                      selectAll = false;
                      $( '#ath').removeClass( "allSelected");
                } else {
                      table.rows().select();
                      selectAll = true;
                      $( '#ath').addClass( "allSelected");
                }
           }); 
           
        <#list listx as x>
           <#if x.codeType!=''  >
             <#if x.condition!="0" || x.insertAble!="0">
           	$.initSelect('${x.codeType}'<#if x.condition!="0">,  '${x.name}ForSearch'</#if><#if x.insertAble!="0">, '${x.name}ForEdit'</#if>);
           	 </#if>
           </#if>
        </#list>
	
		$('#btn-delete').click(function() {
			var ids= table.rows( { selected: true } ).ids();
            if(ids.length==0){
              dialog({
						title : '错误',
						content : '请选择一行数据',
						okValue : '确认',
						ok : true,
						width : 320
			  }).showModal();
              return;
            }
            
            dialog({
			title : '消息',
			content : "是否确认删除",
			ok : function() {
				   var str = ids.join(",");
                   $.ipost("deleteMultiple.mvc", {
					   "ids" : str
				       }, function() {
					  table.draw( false );
		           });		
		    },
			cancel : function() {
			}
		}).show();
   
			
		});
		
		$('#btn-search').click(function() {
			table.ajax.reload();
		});
		
		$('#btn-add').click(function() {
		    $('#${e.primaryColumn.name}ForEdit').val("");
		    <#list listx as x>
				   <#if x.insertAble='1'>
			$('#${x.name}ForEdit').val("");
			$('#${x.name}ForEdit').removeAttr("readonly");
				</#if>
			 </#list>
		    
			showEditDialog();
		});

		//标签
		table = $('#${e.javaName?uncap_first}Table')
				.DataTable(
						{
							"searching" : false,
							"processing" : true,
							select : {
								style : 'multi',
								selector : 'td:first-child'
							},
							"pageLength" : 10,
							"lengthChange" : false,
							"ordering" : false,
							"info" : true,
							"serverSide" : true,
							"ajax" : {
								"url" : "search.mvc",
								"type" : "POST",
								"data" : function(d) {
									return $.extend({}, d, {
									<#assign pos = 0>
										<#list listx as x><#if x.condition!='0'><#if pos=0><#assign pos = 1><#else>,</#if>
										"${x.name}":$('#${x.name}ForSearch').val()</#if></#list>
									});
								},
								"dataSrc" : "data.list"

							},
							rowId : '${e.primaryColumn.name?upper_case}',
							"columns" : [{
							      "data" : null,
							       "className" : "dt-center select-checkbox" ,
							      "defaultContent" : ""
							 }, <#list listx as x><#if x.visiable='1'>              {
								<#if x.codeType==''>
								"data" : "${x.dbName?upper_case}",
								<#else>
								"data" : "${x.dbName?upper_case}_VIEW",
								</#if>
								"className" : "dt-center"
							},</#if>
			   </#list>{"data" : function(row, type, set, meta) {
					var view = "<div class=\"hidden-phone visible-desktop action-buttons\">";
					view = view
							+ " <a href=\"javascript:void(0);\" class=\"green\" onclick=\"update${e.javaName}('"
							+ row.ID
							+ "')\"><i class=\"fa fa-edit \"></i></a>";
					view = view
							+ " <a href=\"javascript:void(0);\" class=\"red\" onclick=\"delete${e.javaName}('"
							+ row.${e.primaryColumn.name?upper_case}
							+ "',"+meta.row+")\"><i class=\"fa fa-trash \"></i></a>"
							+ "</div>";
					return view;
								},
								"className" : "dt-center"
							} ]
						});//标签列表
	});
	
	function showEditDialog(){
		var d = dialog({
			title : '输入',
			width: 800,
			content : document.getElementById("edit-dialog"),
			ok : function() {
				$.ipost("save${e.javaName}.mvc", {
                      "${e.primaryColumn.name}":$('#${e.primaryColumn.name}ForEdit').val()<#list listx as x><#if x.insertAble='1'>,
					   "${x.name}":$('#${x.name}ForEdit').val()</#if></#list>
				}, function() {
					table.ajax.reload();
				});
			},
			cancel : function() {
			}
		});
		d.showModal();
	}
	
	function update${e.javaName}(${e.primaryColumn.name}){
	   $.iget("get${e.javaName}.mvc",{'${e.primaryColumn.name}':${e.primaryColumn.name}},function(result){
	       $('#${e.primaryColumn.name}ForEdit').val(${e.primaryColumn.name});
		    <#list listx as x>
				   <#if x.insertAble='1'>
			$('#${x.name}ForEdit').val(result.data.${e.javaName?uncap_first}.${x.name});
					<#if x.updateAble!='1'>
			$('#${x.name}ForEdit').attr("readonly","readonly");
					</#if>
				</#if>
			 </#list>
		    
			showEditDialog();
	   });
	
	}
	
	function delete${e.javaName}(${e.primaryColumn.name}, rowIndex) {
		dialog({
			title : '消息',
			content : "是否确认删除",
			ok : function() {
				$.ipost("delete${e.javaName}.mvc", {
					"${e.primaryColumn.name}" : ${e.primaryColumn.name}
				}, function() {
					table.row(rowIndex).remove().draw( false );
				});			},
			cancel : function() {
			}
		}).show();
	}
</script>